import { reqCategoryList,reqBannerList,reqFloorList } from "@/api";
//home的VUEX模块

//VUE中的四个核心概念
const state = {
    //存储数据
    categoryList:[],
    bannerList:[],
    floorList:[],
};
const mutations = {
    //直接修改数据
    RECEIVE_CATEGORYLIST(state,categoryList){
        state.categoryList = categoryList;
    },
    RECEIVE_BANNERLIST(state,bannerList){
        state.bannerList = bannerList;
    },
    RECEIVE_FLOORLIST(state,floorList){
        state.floorList = floorList;
    }
};
const actions = {
    //与组件当中的用户对接
    //一般是异步发送请求
    //提交mutations
    async getCategoryList({commit}){
        //发请求拿数据，提交给muatations,存储到
        const result =  await reqCategoryList()
        if(result.code === 200){
            commit("RECEIVE_CATEGORYLIST",result.data);
        }
    },
    async getBannerList({commit}){
        const result = await reqBannerList()
        if(result.code === 200){
            commit("RECEIVE_BANNERLIST",result.data);
        }
    },
    async getFloorList({commit}){
        const result = await reqFloorList()
        if(result.code === 200){
            commit("RECEIVE_FLOORLIST",result.data);
        }
    }
};
const getters = {
    //后面用来简化数据的
}

export default{
    state,
    mutations,
    actions,
    getters,
};